package cn.tedu.blog.api.controller;

import cn.tedu.blog.api.pojo.dto.PageDTO;
import cn.tedu.blog.api.pojo.restful.JsonPage;
import cn.tedu.blog.api.pojo.vo.ArticleStandardVO;
import cn.tedu.blog.api.service.IArticleService;
import cn.tedu.blog.api.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/articles")
@Api(tags = "前台文章查询模块")
public class ArticleController {
    @Autowired
    private IArticleService articleService;
    @ApiOperation("最新文章")
    @ApiOperationSupport(order = 100)
    @GetMapping("/selectNewestArticles")
    public JsonResult selectNewestArticles(){
        log.debug("正在执行查询最新文章");
            List<ArticleStandardVO> list=articleService.selectNewestArticle();
        return JsonResult.ok(list);
    }

    @ApiOperation("热门文章")
    @ApiOperationSupport(order = 200)
    @GetMapping("/selectPopularArticle")
    public JsonResult selectPopularArticle(){
        log.debug("正在查询热门文章");
        List<ArticleStandardVO> list = articleService.selectPopularArticle();
        return JsonResult.ok(list);
    }
    @ApiOperation("管理员推荐文章")
    @ApiOperationSupport(order = 300)
    @GetMapping("/selectIsRecommendArticle")
    public JsonResult selectIsRecommendArticle(){
        log.debug("正在查询管理员推荐文章");
        List<ArticleStandardVO> list = articleService.selectIsRecommendArticle();
        return JsonResult.ok(list);
    }

    @ApiOperation("查询文章列表")
    @ApiOperationSupport(order =400)
    @PostMapping("/selectArticleLists")
    public JsonResult selectArticleLists(@RequestBody PageDTO pageDTO){
        System.out.println("pageDTO = " + pageDTO.toString());
        log.debug("正在查询管理员推荐文章");
        JsonPage<ArticleStandardVO> list =
                articleService.selectArticleLists(pageDTO.getPageNum(), pageDTO.getSize());
        return JsonResult.ok(list);
    }

    @ApiOperation("查询文章的数量")
    @ApiOperationSupport(order =500)
    @GetMapping("/selectArticleNumbers")
    public JsonResult selectArticleCount(){
        log.debug("正在查询管理员推荐文章");
        Long count = articleService.selectArticleCount();
        return JsonResult.ok(count);
    }


}
